<template>
  <div>
    <div style="position: absolute;">
      <el-dropdown @command="handleCommand">
        <el-button type="primary">
          报价项目<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item v-for="(item,index) in xmObj.list" :key="item.id" :command="item.id">{{item.xmname}}</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <xiangmuview :xmId="checkedXmId" :key="'xiangmuview' + checkedXmId" v-if="checkedXmId > 0"></xiangmuview>
  </div>
</template>

<script>
import request from '@/utils/request'
import xiangmuview from "@/views/xiangmu/xiangmuview";
export default {
  components : {xiangmuview},
  data() {
    return {
      sd: {
        pageNum: 1,
        pageSize: 12
      },
      checkedXmId : 0,
      xmObj: {},
    }
  },
  mounted() {
    if(this.$route.query.xmId) this.checkedXmId = this.$route.query.xmId
    this.loadXiangMu()
  },
  methods: {
    loadXiangMu(){
      request({
        url: '/xiangmu/pagexiangmu',
        data: this.sd
      }).then(res => {
        const { data } = res
        this.xmObj = data
        if(this.checkedXmId === 0 && this.xmObj.list && this.xmObj.list.length>=1){
          this.checkedXmId = this.xmObj.list[0].id
        }
      })
    },
    handleCommand(command){
      this.checkedXmId = parseInt(command)
    }
  }
}
</script>

<style scoped>

</style>
